<?= "<?php\n" ?>
declare(strict_types=1);

namespace <?= $namespace ?>Controller\Admin;

use <?= $namespace ?>Model\<?= $modelName ?>;
use <?= $namespace ?>Entity\<?= $entityName ?>;
use SixShop\Core\Request;
use SixShop\System\Middleware\MacroPageMiddleware;
use think\Response;
use think\Route;
use function SixShop\Core\page_response;
use function SixShop\Core\success_response;

/**
 * <?= $tableComment ?: $tableName ?> * 
 * Admin Management Controller for <?= $tableName ?> resource
 * 
 * @package <?= $namespace ?>Controller\Admin
 */
class <?= $controllerName ?>{

    protected array $middlewares = [
        MacroPageMiddleware::class
    ];
    /**
     * Display a listing of the resource
     * GET /{resource}
     */
    public function index(Request $request, <?= $entityName ?> $<?= lcfirst($entityName) ?>): Response
    {
        $params =  $request->get(); // 实际项目中请根据实际情况实现具体参数处理和校验
        $userID = $request->userID; // // 获取用户ID, 实际项目可能需要判断用户所有权限
        // Call entity method
        $page = $<?= lcfirst($entityName) ?>->index<?= ucfirst(str_replace('_', '', $tableName)) ?>($params, $request->pageAndLimit());
        $data = []; // 分页之外的其他数据
        return page_response(page:$page, data:$data, msg:'获取列表数据成功');
    }
    
    /**
     * Show the form for creating a new resource
     * GET /{resource}/create
     */
    public function create(Request $request,<?= $entityName ?> $<?= lcfirst($entityName) ?>): Response
    {
        $userID = $request->userID; // // 获取用户ID, 实际项目可能需要判断用户所有权限
        // Call entity method
        $data = $<?= lcfirst($entityName) ?>->create<?= ucfirst(str_replace('_', '', $tableName)) ?>();
        return success_response(data:$data, msg:'获取新增数据表单成功');
    }
    
    /**
     * Store a newly created resource in storage
     * POST /{resource}
     */
    public function save(Request $request,<?= $entityName ?> $<?= lcfirst($entityName) ?>): Response
    {
        $params = $request->post(); // 实际项目中请根据实际情况实现具体参数处理和校验
        $userID = $request->userID; // // 获取用户ID, 实际项目可能需要判断用户所有权限
        // Call entity method
        $data= $<?= lcfirst($entityName) ?>->save<?= ucfirst(str_replace('_', '', $tableName)) ?>($params);
        return success_response(data:$data, msg:'保存成功');
    }
    
    /**
     * Display the specified resource
     * GET /{resource}/{id}
     */
    public function read(int $id, <?= $entityName ?> $<?= lcfirst($entityName) ?>): Response
    {
        // Call entity method
        $data= $<?= lcfirst($entityName) ?>->read<?= ucfirst(str_replace('_', '', $tableName)) ?>($id);
        return success_response(data:$data, msg:'获取详情数据成功');
    }
    
    /**
     * Show the form for editing the specified resource
     * GET /{resource}/{id}/edit
     */
    public function edit(int $id, Request $request, <?= $entityName ?> $<?= lcfirst($entityName) ?>): Response
    {
        $userID = $request->userID; // 获取用户ID, 实际项目可能需要判断用户所有权限
        // Call entity method
        $data= $<?= lcfirst($entityName) ?>->edit<?= ucfirst(str_replace('_', '', $tableName)) ?>($id);
        return success_response(data:$data, msg:'获取编辑数据表单成功');
    }
    
    /**
     * Update the specified resource in storage
     * PUT/PATCH /{resource}/{id}
     */
    public function update(int $id, Request $request, <?= $entityName ?> $<?= lcfirst($entityName) ?>): Response
    {
        $params = $request->put(); // 实际项目中请根据实际情况实现具体参数处理和校验
        $userID = $request->userID;  // 获取用户ID, 实际项目可能需要判断用户所有权限
        // Call entity method
        $data= $<?= lcfirst($entityName) ?>->update<?= ucfirst(str_replace('_', '', $tableName)) ?>($id, $params);
        return success_response(data:$data, msg:'更新成功');
    }
    
    /**
     * Remove the specified resource from storage
     * DELETE /{resource}/{id}
     */
    public function delete(int $id, Request $request, <?= $entityName ?> $<?= lcfirst($entityName) ?>): Response
    {
        $userID = $request->userID; // // 获取用户ID, 实际项目可能需要判断用户所有权限
        // Call entity method
        $data = $<?= lcfirst($entityName) ?>->delete<?= ucfirst(str_replace('_', '', $tableName)) ?>($id);
        return success_response(data:$data, msg:'删除成功');
    }
}
